package com.droid.lib.controls.demo.view;

import java.util.ArrayList;

import com.droid.lib.controls.demo.R;
import com.droid.lib.controls.demo.adapter.MenuAdapter;
import com.droid.lib.controls.demo.adapter.MenuAdapter.OnClicker;
import com.droid.lib.controls.widget.BottomNavigationBar;
import com.droid.lib.controls.widget.BottomNavigationBar.OnRippleCompleteListener;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;

/*
 *
 * TODO BottomBarFragment
 * Author: zhyc
 * Created on: 2017/10/31 10:53
 *
 */
public class BottomBarFragment extends Fragment {
	BottomNavigationBar bottomNavigationBar;
	ListView listview;
	MenuAdapter adapter;
	LinearLayout llbtnbar;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_bottombar, null);
		listview = (ListView) view.findViewById(R.id.listview);
		llbtnbar = (LinearLayout) view.findViewById(R.id.ll_btnbar);
		adapter = new MenuAdapter(getActivity());
		ArrayList<String> strs = new ArrayList<String>();
		strs.add("CHANGE_TO_NORMAL");
		strs.add("CHANGE_TO_NO_TEXT");
		strs.add("CHANGE_TO_NO_IMAGE");
		strs.add("CHANGE_TO_CHECK_SHOW_TEXT");
		adapter.setList(strs);
		listview.setAdapter(adapter);
		adapter.setOnClicker(new OnClicker() {

			@Override
			public void onclick(int position) {
				switch (position) {
				case 0:
					bottomNavigationBar.setType(BottomNavigationBar.NavShowType.NORMAL);
					break;
				case 1:
					bottomNavigationBar.setType(BottomNavigationBar.NavShowType.NO_TEXT);
					break;
				case 2:
					bottomNavigationBar.setType(BottomNavigationBar.NavShowType.NO_IMAGE);
					break;
				case 3:
					bottomNavigationBar.setType(BottomNavigationBar.NavShowType.CHECKED_SHOW_TEXT);
					break;
				}

			}
		});
		bottomNavigationBar = (BottomNavigationBar) view.findViewById(R.id.bnBar);
		/*
		 * add bottom navigation item param1 bottom text param2 bottom image
		 * checked param3 bottom image unchecked
		 */
		bottomNavigationBar.addItemView("Recents", R.drawable.ic_restore_green_24dp, R.drawable.ic_restore_black_24dp);
		bottomNavigationBar.addItemView("Favorites", R.drawable.ic_insert_emoticon_check_24dp,
				R.drawable.ic_insert_emoticon_black_24dp);
		bottomNavigationBar.addItemView("Nearby", R.drawable.ic_place_green_24dp, R.drawable.ic_place_black_24dp);
		bottomNavigationBar.setRippleColor(Color.WHITE);

		// set Callback
		bottomNavigationBar.setOnItemViewSelectedListener(new BottomNavigationBar.OnItemViewSelectedListener() {
			/**
			 * call when item clicked
			 * 
			 * @param v
			 *            clicked item
			 * @param index
			 *            item index
			 */
			@Override
			public void onItemClcik(View v, int index) {

			}
		});
		bottomNavigationBar.setOnRippleCompleteListener(new OnRippleCompleteListener() {

			@Override
			public void onComplete(BottomNavigationBar rippleView) {
//				llbtnbar.setBackgroundColor(Color.YELLOW);
//				bottomNavigationBar.setBackgroundColor(Color.YELLOW);

			}

			@Override
			public void onInvalidateBefore() {
				llbtnbar.setBackgroundColor(Color.YELLOW);
			}
		});
		return view;
	}
}
